package ThreadPool.lagou.concurrent.demo03;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: 消费者线程
 * @date 2022/5/24 20:59
 */
public class ConsumerThread extends Thread {
    // 防止该参数之后被篡改
    private final MyQueue myQueue;

    public ConsumerThread(MyQueue myQueue){
        this.myQueue = myQueue;
    }

    private boolean flag = true;

    private int index = 0;

    @Override
    public void run() {
        while(flag){
            try {

                System.out.println("\t\t\t消费者消费了,"+myQueue.get());
                index++;
                if(index == 10 ) flag = false;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
